home *** CD-ROM | disk | FTP | other *** search
/ Transformers: Revenge of …he Game: Press Kit (USA) / Transformers - Revenge of the Fallen - The Game - Press Kit (USA).bin / Transformers.swf / scripts / fl / video / NCManager.as < prev    next >
Text File  |  2009-06-19  |  35KB  |  967 lines

  1. package fl.video
  2. {
  3.    import flash.events.NetStatusEvent;
  4.    import flash.events.TimerEvent;
  5.    import flash.net.NetConnection;
  6.    import flash.net.ObjectEncoding;
  7.    import flash.net.Responder;
  8.    import flash.utils.Timer;
  9.    
  10.    use namespace flvplayback_internal;
  11.    
  12.    public class NCManager implements INCManager
  13.    {
  14.       
  15.       public static const VERSION:String = "2.1.0.19";
  16.       
  17.       public static const SHORT_VERSION:String = "2.1";
  18.        
  19.       
  20.       flvplayback_internal var _serverName:String;
  21.       
  22.       flvplayback_internal var _tryNCTimer:Timer;
  23.       
  24.       flvplayback_internal var _autoSenseBW:Boolean;
  25.       
  26.       flvplayback_internal var _fpadZone:Number;
  27.       
  28.       flvplayback_internal var _appName:String;
  29.       
  30.       public const DEFAULT_TIMEOUT:uint = 60000;
  31.       
  32.       flvplayback_internal var _ncConnected:Boolean;
  33.       
  34.       flvplayback_internal var _fpadMgr:FPADManager;
  35.       
  36.       flvplayback_internal var _bitrate:Number;
  37.       
  38.       flvplayback_internal var _timeoutTimer:Timer;
  39.       
  40.       flvplayback_internal var _wrappedURL:String;
  41.       
  42.       flvplayback_internal var _payload:Number;
  43.       
  44.       flvplayback_internal var _nc:NetConnection;
  45.       
  46.       flvplayback_internal var _streamLength:Number;
  47.       
  48.       flvplayback_internal var _connTypeCounter:uint;
  49.       
  50.       flvplayback_internal var _streamWidth:int;
  51.       
  52.       flvplayback_internal var _proxyType:String;
  53.       
  54.       flvplayback_internal var _ncUri:String;
  55.       
  56.       flvplayback_internal var _contentPath:String;
  57.       
  58.       flvplayback_internal var _smilMgr:SMILManager;
  59.       
  60.       flvplayback_internal var _streamHeight:int;
  61.       
  62.       flvplayback_internal var _isRTMP:Boolean;
  63.       
  64.       flvplayback_internal var _tryNC:Array;
  65.       
  66.       flvplayback_internal var _streams:Array;
  67.       
  68.       flvplayback_internal var _owner:VideoPlayer;
  69.       
  70.       flvplayback_internal var _portNumber:String;
  71.       
  72.       flvplayback_internal var _streamName:String;
  73.       
  74.       flvplayback_internal var _objectEncoding:uint;
  75.       
  76.       public var fallbackServerName:String;
  77.       
  78.       flvplayback_internal var _protocol:String;
  79.       
  80.       public function NCManager()
  81.       {
  82.          super();
  83.          _fpadZone = NaN;
  84.          _objectEncoding = ObjectEncoding.AMF0;
  85.          _proxyType = "best";
  86.          _timeoutTimer = new Timer(DEFAULT_TIMEOUT);
  87.          flvplayback_internal::_timeoutTimer.addEventListener(TimerEvent.TIMER,this._onFMSConnectTimeOut);
  88.          _tryNCTimer = new Timer(1500,1);
  89.          flvplayback_internal::_tryNCTimer.addEventListener(TimerEvent.TIMER,this.nextConnect);
  90.          initNCInfo();
  91.          initOtherInfo();
  92.          _nc = null;
  93.          _ncConnected = false;
  94.       }
  95.       
  96.       flvplayback_internal static function stripFrontAndBackWhiteSpace(param1:String) : String
  97.       {
  98.          var _loc2_:uint = 0;
  99.          var _loc3_:uint = param1.length;
  100.          var _loc4_:int = 0;
  101.          var _loc5_:int = _loc3_;
  102.          _loc2_ = 0;
  103.          for(; _loc2_ < _loc3_; _loc2_++)
  104.          {
  105.             switch(param1.charCodeAt(_loc2_))
  106.             {
  107.                case 9:
  108.                case 10:
  109.                case 13:
  110.                case 32:
  111.                   continue;
  112.                default:
  113.                   _loc4_ = _loc2_;
  114.             }
  115.          }
  116.          _loc2_ = _loc3_;
  117.          for(; _loc2_ >= 0; _loc2_--)
  118.          {
  119.             switch(param1.charCodeAt(_loc2_))
  120.             {
  121.                case 9:
  122.                case 10:
  123.                case 13:
  124.                case 32:
  125.                   continue;
  126.                default:
  127.                   _loc5_ = _loc2_ + 1;
  128.             }
  129.          }
  130.          if(_loc5_ <= _loc4_)
  131.          {
  132.             return "";
  133.          }
  134.          return param1.slice(_loc4_,_loc5_);
  135.       }
  136.       
  137.       flvplayback_internal function initNCInfo() : void
  138.       {
  139.          _isRTMP = false;
  140.          _serverName = null;
  141.          _wrappedURL = null;
  142.          _portNumber = null;
  143.          _appName = null;
  144.       }
  145.       
  146.       flvplayback_internal function cleanConns() : void
  147.       {
  148.          var _loc1_:uint = 0;
  149.          flvplayback_internal::_tryNCTimer.reset();
  150.          if(flvplayback_internal::_tryNC != null)
  151.          {
  152.             _loc1_ = 0;
  153.             while(_loc1_ < flvplayback_internal::_tryNC.length)
  154.             {
  155.                if(flvplayback_internal::_tryNC[_loc1_] != null)
  156.                {
  157.                   flvplayback_internal::_tryNC[_loc1_].removeEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::connectOnStatus);
  158.                   if(flvplayback_internal::_tryNC[_loc1_].client.pending)
  159.                   {
  160.                      flvplayback_internal::_tryNC[_loc1_].addEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::disconnectOnStatus);
  161.                   }
  162.                   else
  163.                   {
  164.                      flvplayback_internal::_tryNC[_loc1_].close();
  165.                   }
  166.                }
  167.                flvplayback_internal::_tryNC[_loc1_] = null;
  168.                _loc1_++;
  169.             }
  170.             _tryNC = null;
  171.          }
  172.       }
  173.       
  174.       public function get streamWidth() : int
  175.       {
  176.          return flvplayback_internal::_streamWidth;
  177.       }
  178.       
  179.       public function connectToURL(param1:String) : Boolean
  180.       {
  181.          var canReuse:Boolean = false;
  182.          var name:String = null;
  183.          var url:String = param1;
  184.          initOtherInfo();
  185.          _contentPath = url;
  186.          if(flvplayback_internal::_contentPath == null || flvplayback_internal::_contentPath == "")
  187.          {
  188.             throw new VideoError(VideoError.INVALID_SOURCE);
  189.          }
  190.          var parseResults:ParseResults = parseURL(flvplayback_internal::_contentPath);
  191.          if(parseResults.streamName == null || parseResults.streamName == "")
  192.          {
  193.             throw new VideoError(VideoError.INVALID_SOURCE,url);
  194.          }
  195.          if(parseResults.isRTMP)
  196.          {
  197.             canReuse = canReuseOldConnection(parseResults);
  198.             _isRTMP = true;
  199.             _protocol = parseResults.protocol;
  200.             _streamName = parseResults.streamName;
  201.             _serverName = parseResults.serverName;
  202.             _wrappedURL = parseResults.wrappedURL;
  203.             _portNumber = parseResults.portNumber;
  204.             _appName = parseResults.appName;
  205.             if(flvplayback_internal::_appName == null || flvplayback_internal::_appName == "" || flvplayback_internal::_streamName == null || flvplayback_internal::_streamName == "")
  206.             {
  207.                throw new VideoError(VideoError.INVALID_SOURCE,url);
  208.             }
  209.             _autoSenseBW = flvplayback_internal::_streamName.indexOf(",") >= 0;
  210.             return canReuse || connectRTMP();
  211.          }
  212.          name = parseResults.streamName;
  213.          if(name.indexOf("?") < 0 && (name.length < 4 || name.slice(-4).toLowerCase() != ".txt") && (name.length < 4 || name.slice(-4).toLowerCase() != ".xml") && (name.length < 5 || name.slice(-5).toLowerCase() != ".smil"))
  214.          {
  215.             canReuse = canReuseOldConnection(parseResults);
  216.             _isRTMP = false;
  217.             _streamName = name;
  218.             return canReuse || connectHTTP();
  219.          }
  220.          if(name.indexOf("/fms/fpad") >= 0)
  221.          {
  222.             try
  223.             {
  224.                return connectFPAD(name);
  225.             }
  226.             catch(err:Error)
  227.             {
  228.             }
  229.          }
  230.          _smilMgr = new SMILManager(this);
  231.          return flvplayback_internal::_smilMgr.connectXML(name);
  232.       }
  233.       
  234.       public function get streamName() : String
  235.       {
  236.          return flvplayback_internal::_streamName;
  237.       }
  238.       
  239.       flvplayback_internal function reconnectOnStatus(param1:NetStatusEvent) : void
  240.       {
  241.          if(param1.info.code == "NetConnection.Connect.Failed" || param1.info.code == "NetConnection.Connect.Rejected")
  242.          {
  243.             _nc = null;
  244.             _ncConnected = false;
  245.             flvplayback_internal::_owner.ncReconnected();
  246.          }
  247.       }
  248.       
  249.       public function get videoPlayer() : VideoPlayer
  250.       {
  251.          return flvplayback_internal::_owner;
  252.       }
  253.       
  254.       flvplayback_internal function getStreamLengthResult(param1:Number) : void
  255.       {
  256.          if(param1 > 0)
  257.          {
  258.             _streamLength = param1;
  259.          }
  260.          flvplayback_internal::_owner.ncConnected();
  261.       }
  262.       
  263.       flvplayback_internal function canReuseOldConnection(param1:ParseResults) : Boolean
  264.       {
  265.          if(flvplayback_internal::_nc == null || !flvplayback_internal::_ncConnected)
  266.          {
  267.             return false;
  268.          }
  269.          if(!param1.isRTMP)
  270.          {
  271.             if(!flvplayback_internal::_isRTMP)
  272.             {
  273.                return true;
  274.             }
  275.             flvplayback_internal::_owner.close();
  276.             _nc = null;
  277.             _ncConnected = false;
  278.             initNCInfo();
  279.             return false;
  280.          }
  281.          if(flvplayback_internal::_isRTMP)
  282.          {
  283.             if(param1.serverName == flvplayback_internal::_serverName && param1.appName == flvplayback_internal::_appName && param1.protocol == flvplayback_internal::_protocol && param1.portNumber == flvplayback_internal::_portNumber && param1.wrappedURL == flvplayback_internal::_wrappedURL)
  284.             {
  285.                return true;
  286.             }
  287.             flvplayback_internal::_owner.close();
  288.             _nc = null;
  289.             _ncConnected = false;
  290.          }
  291.          initNCInfo();
  292.          return false;
  293.       }
  294.       
  295.       public function helperDone(param1:Object, param2:Boolean) : void
  296.       {
  297.          var _loc3_:ParseResults = null;
  298.          var _loc4_:* = null;
  299.          var _loc7_:Number = NaN;
  300.          if(!param2)
  301.          {
  302.             _nc = null;
  303.             _ncConnected = false;
  304.             flvplayback_internal::_owner.ncConnected();
  305.             _smilMgr = null;
  306.             _fpadMgr = null;
  307.             return;
  308.          }
  309.          var _loc5_:Boolean = false;
  310.          if(param1 == flvplayback_internal::_fpadMgr)
  311.          {
  312.             _loc4_ = flvplayback_internal::_fpadMgr.rtmpURL;
  313.             _fpadMgr = null;
  314.             _loc3_ = parseURL(_loc4_);
  315.             _isRTMP = _loc3_.isRTMP;
  316.             _protocol = _loc3_.protocol;
  317.             _serverName = _loc3_.serverName;
  318.             _portNumber = _loc3_.portNumber;
  319.             _wrappedURL = _loc3_.wrappedURL;
  320.             _appName = _loc3_.appName;
  321.             _streamName = _loc3_.streamName;
  322.             _loc7_ = flvplayback_internal::_fpadZone;
  323.             _fpadZone = NaN;
  324.             connectRTMP();
  325.             _fpadZone = _loc7_;
  326.             return;
  327.          }
  328.          if(param1 != flvplayback_internal::_smilMgr)
  329.          {
  330.             return;
  331.          }
  332.          _streamWidth = flvplayback_internal::_smilMgr.width;
  333.          _streamHeight = flvplayback_internal::_smilMgr.height;
  334.          if((_loc4_ = flvplayback_internal::_smilMgr.baseURLAttr[0]) != null && _loc4_ != "")
  335.          {
  336.             if(_loc4_.charAt(_loc4_.length - 1) != "/")
  337.             {
  338.                _loc4_ += "/";
  339.             }
  340.             _loc3_ = parseURL(_loc4_);
  341.             _isRTMP = _loc3_.isRTMP;
  342.             _loc5_ = true;
  343.             _streamName = _loc3_.streamName;
  344.             if(flvplayback_internal::_isRTMP)
  345.             {
  346.                _protocol = _loc3_.protocol;
  347.                _serverName = _loc3_.serverName;
  348.                _portNumber = _loc3_.portNumber;
  349.                _wrappedURL = _loc3_.wrappedURL;
  350.                _appName = _loc3_.appName;
  351.                if(flvplayback_internal::_appName == null || flvplayback_internal::_appName == "")
  352.                {
  353.                   _smilMgr = null;
  354.                   throw new VideoError(VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  355.                }
  356.                if(flvplayback_internal::_smilMgr.baseURLAttr.length > 1)
  357.                {
  358.                   _loc3_ = parseURL(flvplayback_internal::_smilMgr.baseURLAttr[1]);
  359.                   if(_loc3_.serverName != null)
  360.                   {
  361.                      fallbackServerName = _loc3_.serverName;
  362.                   }
  363.                }
  364.             }
  365.          }
  366.          _streams = flvplayback_internal::_smilMgr.videoTags;
  367.          _smilMgr = null;
  368.          var _loc6_:uint = 0;
  369.          while(_loc6_ < flvplayback_internal::_streams.length)
  370.          {
  371.             _loc4_ = flvplayback_internal::_streams[_loc6_].src;
  372.             _loc3_ = parseURL(_loc4_);
  373.             if(!_loc5_)
  374.             {
  375.                _isRTMP = _loc3_.isRTMP;
  376.                _loc5_ = true;
  377.                if(flvplayback_internal::_isRTMP)
  378.                {
  379.                   _protocol = _loc3_.protocol;
  380.                   if(flvplayback_internal::_streams.length > 1)
  381.                   {
  382.                      throw new VideoError(VideoError.INVALID_XML,"Cannot switch between multiple absolute RTMP URLs, must use meta tag base attribute.");
  383.                   }
  384.                   _serverName = _loc3_.serverName;
  385.                   _portNumber = _loc3_.portNumber;
  386.                   _wrappedURL = _loc3_.wrappedURL;
  387.                   _appName = _loc3_.appName;
  388.                   if(flvplayback_internal::_appName == null || flvplayback_internal::_appName == "")
  389.                   {
  390.                      throw new VideoError(VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  391.                   }
  392.                }
  393.                else if(_loc3_.streamName.indexOf("/fms/fpad") >= 0 && flvplayback_internal::_streams.length > 1)
  394.                {
  395.                   throw new VideoError(VideoError.INVALID_XML,"Cannot switch between multiple absolute fpad URLs, must use meta tag base attribute.");
  396.                }
  397.             }
  398.             else if(flvplayback_internal::_streamName != null && flvplayback_internal::_streamName != "" && !_loc3_.isRelative && flvplayback_internal::_streams.length > 1)
  399.             {
  400.                throw new VideoError(VideoError.INVALID_XML,"When using meta tag base attribute, cannot use absolute URLs for video or ref tag src attributes.");
  401.             }
  402.             flvplayback_internal::_streams[_loc6_].parseResults = _loc3_;
  403.             _loc6_++;
  404.          }
  405.          _autoSenseBW = flvplayback_internal::_streams.length > 1;
  406.          if(!flvplayback_internal::_autoSenseBW)
  407.          {
  408.             if(flvplayback_internal::_streamName != null)
  409.             {
  410.                _streamName += flvplayback_internal::_streams[0].parseResults.streamName;
  411.             }
  412.             else
  413.             {
  414.                _streamName = flvplayback_internal::_streams[0].parseResults.streamName;
  415.             }
  416.             if(flvplayback_internal::_isRTMP && flvplayback_internal::_streamName.substr(-4).toLowerCase() == ".flv")
  417.             {
  418.                _streamName = flvplayback_internal::_streamName.substr(0,flvplayback_internal::_streamName.length - 4);
  419.             }
  420.             _streamLength = flvplayback_internal::_streams[0].dur;
  421.          }
  422.          if(flvplayback_internal::_isRTMP)
  423.          {
  424.             connectRTMP();
  425.          }
  426.          else if(flvplayback_internal::_streamName != null && flvplayback_internal::_streamName.indexOf("/fms/fpad") >= 0)
  427.          {
  428.             connectFPAD(flvplayback_internal::_streamName);
  429.          }
  430.          else
  431.          {
  432.             if(flvplayback_internal::_autoSenseBW)
  433.             {
  434.                bitrateMatch();
  435.             }
  436.             connectHTTP();
  437.             flvplayback_internal::_owner.ncConnected();
  438.          }
  439.       }
  440.       
  441.       public function getProperty(param1:String) : *
  442.       {
  443.          switch(param1)
  444.          {
  445.             case "fallbackServerName":
  446.                return fallbackServerName;
  447.             case "fpadZone":
  448.                return flvplayback_internal::_fpadZone;
  449.             case "objectEncoding":
  450.                return flvplayback_internal::_objectEncoding;
  451.             case "proxyType":
  452.                return flvplayback_internal::_proxyType;
  453.             default:
  454.                throw new VideoError(VideoError.UNSUPPORTED_PROPERTY,param1);
  455.          }
  456.       }
  457.       
  458.       flvplayback_internal function connectRTMP() : Boolean
  459.       {
  460.          flvplayback_internal::_timeoutTimer.stop();
  461.          flvplayback_internal::_timeoutTimer.start();
  462.          _tryNC = new Array();
  463.          var _loc1_:int = flvplayback_internal::_protocol == "rtmp:/" || flvplayback_internal::_protocol == "rtmpe:/" ? 2 : 1;
  464.          var _loc2_:uint = 0;
  465.          while(_loc2_ < _loc1_)
  466.          {
  467.             flvplayback_internal::_tryNC[_loc2_] = new NetConnection();
  468.             flvplayback_internal::_tryNC[_loc2_].objectEncoding = flvplayback_internal::_objectEncoding;
  469.             flvplayback_internal::_tryNC[_loc2_].proxyType = flvplayback_internal::_proxyType;
  470.             if(!isNaN(flvplayback_internal::_fpadZone))
  471.             {
  472.                flvplayback_internal::_tryNC[_loc2_].fpadZone = flvplayback_internal::_fpadZone;
  473.             }
  474.             flvplayback_internal::_tryNC[_loc2_].client = new ConnectClient(this,flvplayback_internal::_tryNC[_loc2_],_loc2_);
  475.             flvplayback_internal::_tryNC[_loc2_].addEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::connectOnStatus);
  476.             _loc2_++;
  477.          }
  478.          nextConnect();
  479.          return false;
  480.       }
  481.       
  482.       public function reconnect() : void
  483.       {
  484.          if(!flvplayback_internal::_isRTMP)
  485.          {
  486.             throw new Error("Cannot call reconnect on an http connection");
  487.          }
  488.          flvplayback_internal::_nc.client = new ReconnectClient(this);
  489.          flvplayback_internal::_nc.addEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::reconnectOnStatus);
  490.          flvplayback_internal::_nc.connect(flvplayback_internal::_ncUri,false);
  491.       }
  492.       
  493.       public function get netConnection() : NetConnection
  494.       {
  495.          return flvplayback_internal::_nc;
  496.       }
  497.       
  498.       public function get bitrate() : Number
  499.       {
  500.          return flvplayback_internal::_bitrate;
  501.       }
  502.       
  503.       public function setProperty(param1:String, param2:*) : void
  504.       {
  505.          switch(param1)
  506.          {
  507.             case "fallbackServerName":
  508.                fallbackServerName = String(param2);
  509.                break;
  510.             case "fpadZone":
  511.                _fpadZone = Number(param2);
  512.                break;
  513.             case "objectEncoding":
  514.                _objectEncoding = uint(param2);
  515.                break;
  516.             case "proxyType":
  517.                _proxyType = String(param2);
  518.                break;
  519.             default:
  520.                throw new VideoError(VideoError.UNSUPPORTED_PROPERTY,param1);
  521.          }
  522.       }
  523.       
  524.       public function get timeout() : uint
  525.       {
  526.          return flvplayback_internal::_timeoutTimer.delay;
  527.       }
  528.       
  529.       flvplayback_internal function connectHTTP() : Boolean
  530.       {
  531.          _nc = new NetConnection();
  532.          flvplayback_internal::_nc.connect(null);
  533.          _ncConnected = true;
  534.          return true;
  535.       }
  536.       
  537.       public function set videoPlayer(param1:VideoPlayer) : void
  538.       {
  539.          _owner = param1;
  540.       }
  541.       
  542.       flvplayback_internal function bitrateMatch() : void
  543.       {
  544.          var _loc1_:Number = flvplayback_internal::_bitrate;
  545.          if(isNaN(_loc1_))
  546.          {
  547.             _loc1_ = 0;
  548.          }
  549.          var _loc2_:uint = flvplayback_internal::_streams.length;
  550.          var _loc3_:uint = 0;
  551.          while(_loc3_ < flvplayback_internal::_streams.length)
  552.          {
  553.             if(isNaN(flvplayback_internal::_streams[_loc3_].bitrate) || _loc1_ >= flvplayback_internal::_streams[_loc3_].bitrate)
  554.             {
  555.                _loc2_ = _loc3_;
  556.                break;
  557.             }
  558.             _loc3_++;
  559.          }
  560.          if(_loc2_ == flvplayback_internal::_streams.length)
  561.          {
  562.             throw new VideoError(VideoError.NO_BITRATE_MATCH);
  563.          }
  564.          if(flvplayback_internal::_streamName != null)
  565.          {
  566.             _streamName += flvplayback_internal::_streams[_loc2_].src;
  567.          }
  568.          else
  569.          {
  570.             _streamName = flvplayback_internal::_streams[_loc2_].src;
  571.          }
  572.          if(flvplayback_internal::_isRTMP && flvplayback_internal::_streamName.substr(-4).toLowerCase() == ".flv")
  573.          {
  574.             _streamName = flvplayback_internal::_streamName.substr(0,flvplayback_internal::_streamName.length - 4);
  575.          }
  576.          _streamLength = flvplayback_internal::_streams[_loc2_].dur;
  577.       }
  578.       
  579.       flvplayback_internal function disconnectOnStatus(param1:NetStatusEvent) : void
  580.       {
  581.          if(param1.info.code == "NetConnection.Connect.Success")
  582.          {
  583.             param1.target.removeEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::disconnectOnStatus);
  584.             param1.target.close();
  585.          }
  586.       }
  587.       
  588.       flvplayback_internal function nextConnect(param1:TimerEvent = null) : void
  589.       {
  590.          var _loc2_:String = null;
  591.          var _loc3_:String = null;
  592.          if(flvplayback_internal::_connTypeCounter == 0)
  593.          {
  594.             _loc2_ = flvplayback_internal::_protocol;
  595.             _loc3_ = flvplayback_internal::_portNumber;
  596.          }
  597.          else
  598.          {
  599.             _loc3_ = null;
  600.             if(flvplayback_internal::_protocol == "rtmp:/")
  601.             {
  602.                _loc2_ = "rtmpt:/";
  603.             }
  604.             else
  605.             {
  606.                if(flvplayback_internal::_protocol != "rtmpe:/")
  607.                {
  608.                   flvplayback_internal::_tryNC.pop();
  609.                   return;
  610.                }
  611.                _loc2_ = "rtmpte:/";
  612.             }
  613.          }
  614.          var _loc4_:String = _loc2_ + (flvplayback_internal::_serverName == null ? "" : "/" + flvplayback_internal::_serverName + (_loc3_ == null ? "" : ":" + _loc3_) + "/") + (flvplayback_internal::_wrappedURL == null ? "" : flvplayback_internal::_wrappedURL + "/") + flvplayback_internal::_appName;
  615.          flvplayback_internal::_tryNC[flvplayback_internal::_connTypeCounter].client.pending = true;
  616.          flvplayback_internal::_tryNC[flvplayback_internal::_connTypeCounter].connect(_loc4_,flvplayback_internal::_autoSenseBW);
  617.          if(flvplayback_internal::_connTypeCounter < flvplayback_internal::_tryNC.length - 1)
  618.          {
  619.             ++_connTypeCounter;
  620.             flvplayback_internal::_tryNCTimer.reset();
  621.             flvplayback_internal::_tryNCTimer.start();
  622.          }
  623.       }
  624.       
  625.       flvplayback_internal function connectFPAD(param1:String) : Boolean
  626.       {
  627.          var _loc2_:Object = /^(.+)(\?|\&)(uri=)([^&]+)(\&.*)?$/.exec(param1);
  628.          if(_loc2_ == null)
  629.          {
  630.             throw new VideoError(VideoError.INVALID_SOURCE,"fpad url must include uri parameter: " + param1);
  631.          }
  632.          var _loc3_:String = _loc2_[1] + _loc2_[2];
  633.          var _loc4_:String = _loc2_[4];
  634.          var _loc5_:String = _loc2_[5] == undefined ? "" : _loc2_[5];
  635.          var _loc6_:ParseResults;
  636.          if(!(_loc6_ = parseURL(_loc4_)).isRTMP)
  637.          {
  638.             throw new VideoError(VideoError.INVALID_SOURCE,"fpad url uri parameter must be rtmp url: " + param1);
  639.          }
  640.          _fpadMgr = new FPADManager(this);
  641.          return flvplayback_internal::_fpadMgr.connectXML(_loc3_,_loc4_,_loc5_,_loc6_);
  642.       }
  643.       
  644.       public function get isRTMP() : Boolean
  645.       {
  646.          return flvplayback_internal::_isRTMP;
  647.       }
  648.       
  649.       public function get streamLength() : Number
  650.       {
  651.          return flvplayback_internal::_streamLength;
  652.       }
  653.       
  654.       public function connectAgain() : Boolean
  655.       {
  656.          var _loc1_:int = flvplayback_internal::_appName.indexOf("/");
  657.          if(_loc1_ < 0)
  658.          {
  659.             _loc1_ = flvplayback_internal::_streamName.indexOf("/");
  660.             if(_loc1_ >= 0)
  661.             {
  662.                _appName += "/";
  663.                _appName += flvplayback_internal::_streamName.slice(0,_loc1_);
  664.                _streamName = flvplayback_internal::_streamName.slice(_loc1_ + 1);
  665.             }
  666.             return false;
  667.          }
  668.          var _loc2_:* = flvplayback_internal::_appName.slice(_loc1_ + 1);
  669.          _loc2_ += "/";
  670.          _loc2_ += flvplayback_internal::_streamName;
  671.          _streamName = _loc2_;
  672.          _appName = flvplayback_internal::_appName.slice(0,_loc1_);
  673.          close();
  674.          _payload = 0;
  675.          _connTypeCounter = 0;
  676.          cleanConns();
  677.          connectRTMP();
  678.          return true;
  679.       }
  680.       
  681.       flvplayback_internal function parseURL(param1:String) : ParseResults
  682.       {
  683.          var _loc5_:int = 0;
  684.          var _loc6_:int = 0;
  685.          var _loc7_:String = null;
  686.          var _loc8_:ParseResults = null;
  687.          var _loc2_:ParseResults = new ParseResults();
  688.          var _loc3_:int = 0;
  689.          var _loc4_:int;
  690.          if((_loc4_ = param1.indexOf(":/",_loc3_)) >= 0)
  691.          {
  692.             _loc4_ += 2;
  693.             _loc2_.protocol = param1.slice(_loc3_,_loc4_).toLowerCase();
  694.             _loc2_.isRelative = false;
  695.          }
  696.          else
  697.          {
  698.             _loc2_.isRelative = true;
  699.          }
  700.          if(_loc2_.protocol != null && (_loc2_.protocol == "rtmp:/" || _loc2_.protocol == "rtmpt:/" || _loc2_.protocol == "rtmps:/" || _loc2_.protocol == "rtmpe:/" || _loc2_.protocol == "rtmpte:/"))
  701.          {
  702.             _loc2_.isRTMP = true;
  703.             _loc3_ = _loc4_;
  704.             if(param1.charAt(_loc3_) == "/")
  705.             {
  706.                _loc3_++;
  707.                _loc5_ = param1.indexOf(":",_loc3_);
  708.                if((_loc6_ = param1.indexOf("/",_loc3_)) < 0)
  709.                {
  710.                   if(_loc5_ < 0)
  711.                   {
  712.                      _loc2_.serverName = param1.slice(_loc3_);
  713.                   }
  714.                   else
  715.                   {
  716.                      _loc4_ = _loc5_;
  717.                      _loc2_.portNumber = param1.slice(_loc3_,_loc4_);
  718.                      _loc3_ = _loc4_ + 1;
  719.                      _loc2_.serverName = param1.slice(_loc3_);
  720.                   }
  721.                   return _loc2_;
  722.                }
  723.                if(_loc5_ >= 0 && _loc5_ < _loc6_)
  724.                {
  725.                   _loc4_ = _loc5_;
  726.                   _loc2_.serverName = param1.slice(_loc3_,_loc4_);
  727.                   _loc3_ = _loc4_ + 1;
  728.                   _loc4_ = _loc6_;
  729.                   _loc2_.portNumber = param1.slice(_loc3_,_loc4_);
  730.                }
  731.                else
  732.                {
  733.                   _loc4_ = _loc6_;
  734.                   _loc2_.serverName = param1.slice(_loc3_,_loc4_);
  735.                }
  736.                _loc3_ = _loc4_ + 1;
  737.             }
  738.             if(param1.charAt(_loc3_) == "?")
  739.             {
  740.                _loc7_ = param1.slice(_loc3_ + 1);
  741.                if((_loc8_ = parseURL(_loc7_)).protocol == null || !_loc8_.isRTMP)
  742.                {
  743.                   throw new VideoError(VideoError.INVALID_SOURCE,param1);
  744.                }
  745.                _loc2_.wrappedURL = "?";
  746.                _loc2_.wrappedURL += _loc8_.protocol;
  747.                if(_loc8_.serverName != null)
  748.                {
  749.                   _loc2_.wrappedURL += "/";
  750.                   _loc2_.wrappedURL += _loc8_.serverName;
  751.                }
  752.                if(_loc8_.portNumber != null)
  753.                {
  754.                   _loc2_.wrappedURL += ":" + _loc8_.portNumber;
  755.                }
  756.                if(_loc8_.wrappedURL != null)
  757.                {
  758.                   _loc2_.wrappedURL += "/";
  759.                   _loc2_.wrappedURL += _loc8_.wrappedURL;
  760.                }
  761.                _loc2_.appName = _loc8_.appName;
  762.                _loc2_.streamName = _loc8_.streamName;
  763.                return _loc2_;
  764.             }
  765.             if((_loc4_ = param1.indexOf("/",_loc3_)) < 0)
  766.             {
  767.                _loc2_.appName = param1.slice(_loc3_);
  768.                return _loc2_;
  769.             }
  770.             _loc2_.appName = param1.slice(_loc3_,_loc4_);
  771.             _loc3_ = _loc4_ + 1;
  772.             if((_loc4_ = param1.indexOf("/",_loc3_)) < 0)
  773.             {
  774.                _loc2_.streamName = param1.slice(_loc3_);
  775.                if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  776.                {
  777.                   _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  778.                }
  779.                return _loc2_;
  780.             }
  781.             _loc2_.appName += "/";
  782.             _loc2_.appName += param1.slice(_loc3_,_loc4_);
  783.             _loc3_ = _loc4_ + 1;
  784.             _loc2_.streamName = param1.slice(_loc3_);
  785.             if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  786.             {
  787.                _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  788.             }
  789.          }
  790.          else
  791.          {
  792.             _loc2_.isRTMP = false;
  793.             _loc2_.streamName = param1;
  794.          }
  795.          return _loc2_;
  796.       }
  797.       
  798.       flvplayback_internal function initOtherInfo() : void
  799.       {
  800.          _contentPath = null;
  801.          _streamName = null;
  802.          _streamWidth = -1;
  803.          _streamHeight = -1;
  804.          _streamLength = NaN;
  805.          _streams = null;
  806.          _autoSenseBW = false;
  807.          _payload = 0;
  808.          _connTypeCounter = 0;
  809.          cleanConns();
  810.       }
  811.       
  812.       public function set timeout(param1:uint) : void
  813.       {
  814.          flvplayback_internal::_timeoutTimer.delay = param1;
  815.       }
  816.       
  817.       flvplayback_internal function _onFMSConnectTimeOut(param1:TimerEvent = null) : void
  818.       {
  819.          cleanConns();
  820.          _nc = null;
  821.          _ncConnected = false;
  822.          if(!connectAgain())
  823.          {
  824.             flvplayback_internal::_owner.ncConnected();
  825.          }
  826.       }
  827.       
  828.       public function get streamHeight() : int
  829.       {
  830.          return flvplayback_internal::_streamHeight;
  831.       }
  832.       
  833.       flvplayback_internal function connectOnStatus(param1:NetStatusEvent) : void
  834.       {
  835.          var _loc2_:ParseResults = null;
  836.          param1.target.client.pending = false;
  837.          if(param1.info.code == "NetConnection.Connect.Success")
  838.          {
  839.             _nc = flvplayback_internal::_tryNC[param1.target.client.connIndex];
  840.             cleanConns();
  841.          }
  842.          else if(param1.info.code == "NetConnection.Connect.Rejected" && param1.info.ex != null && param1.info.ex.code == 302)
  843.          {
  844.             _connTypeCounter = 0;
  845.             cleanConns();
  846.             _loc2_ = parseURL(param1.info.ex.redirect);
  847.             if(_loc2_.isRTMP)
  848.             {
  849.                _protocol = _loc2_.protocol;
  850.                _serverName = _loc2_.serverName;
  851.                _wrappedURL = _loc2_.wrappedURL;
  852.                _portNumber = _loc2_.portNumber;
  853.                _appName = _loc2_.appName;
  854.                if(_loc2_.streamName != null)
  855.                {
  856.                   _appName += "/" + _loc2_.streamName;
  857.                }
  858.                connectRTMP();
  859.             }
  860.             else
  861.             {
  862.                tryFallBack();
  863.             }
  864.          }
  865.          else if((param1.info.code == "NetConnection.Connect.Failed" || param1.info.code == "NetConnection.Connect.Rejected") && param1.target.client.connIndex == flvplayback_internal::_tryNC.length - 1)
  866.          {
  867.             if(!connectAgain())
  868.             {
  869.                tryFallBack();
  870.             }
  871.          }
  872.       }
  873.       
  874.       flvplayback_internal function onReconnected() : void
  875.       {
  876.          _ncConnected = true;
  877.          flvplayback_internal::_owner.ncReconnected();
  878.       }
  879.       
  880.       flvplayback_internal function tryFallBack() : void
  881.       {
  882.          if(flvplayback_internal::_serverName == fallbackServerName || fallbackServerName == null)
  883.          {
  884.             _nc = null;
  885.             _ncConnected = false;
  886.             flvplayback_internal::_owner.ncConnected();
  887.          }
  888.          else
  889.          {
  890.             _connTypeCounter = 0;
  891.             cleanConns();
  892.             _serverName = fallbackServerName;
  893.             connectRTMP();
  894.          }
  895.       }
  896.       
  897.       public function set bitrate(param1:Number) : void
  898.       {
  899.          if(!flvplayback_internal::_isRTMP)
  900.          {
  901.             _bitrate = param1;
  902.          }
  903.       }
  904.       
  905.       flvplayback_internal function onConnected(param1:NetConnection, param2:Number) : void
  906.       {
  907.          var _loc3_:Array = null;
  908.          var _loc4_:uint = 0;
  909.          var _loc5_:String = null;
  910.          flvplayback_internal::_timeoutTimer.stop();
  911.          param1.removeEventListener(NetStatusEvent.NET_STATUS,flvplayback_internal::connectOnStatus);
  912.          _nc = param1;
  913.          _ncUri = flvplayback_internal::_nc.uri;
  914.          _ncConnected = true;
  915.          if(flvplayback_internal::_autoSenseBW)
  916.          {
  917.             _bitrate = param2 * 1024;
  918.             if(flvplayback_internal::_streams != null)
  919.             {
  920.                bitrateMatch();
  921.             }
  922.             else
  923.             {
  924.                _loc3_ = flvplayback_internal::_streamName.split(",");
  925.                _loc4_ = 0;
  926.                while(_loc4_ < _loc3_.length)
  927.                {
  928.                   _loc5_ = stripFrontAndBackWhiteSpace(_loc3_[_loc4_]);
  929.                   if(_loc4_ + 1 >= _loc3_.length)
  930.                   {
  931.                      _streamName = _loc5_;
  932.                      break;
  933.                   }
  934.                   if(param2 <= Number(_loc3_[_loc4_ + 1]))
  935.                   {
  936.                      _streamName = _loc5_;
  937.                      break;
  938.                   }
  939.                   _loc4_ += 2;
  940.                }
  941.                if(flvplayback_internal::_streamName.slice(-4).toLowerCase() == ".flv")
  942.                {
  943.                   _streamName = flvplayback_internal::_streamName.slice(0,-4);
  944.                }
  945.             }
  946.          }
  947.          if(!flvplayback_internal::_owner.isLive && isNaN(flvplayback_internal::_streamLength))
  948.          {
  949.             flvplayback_internal::_nc.call("getStreamLength",new Responder(flvplayback_internal::getStreamLengthResult),flvplayback_internal::_streamName);
  950.          }
  951.          else
  952.          {
  953.             flvplayback_internal::_owner.ncConnected();
  954.          }
  955.       }
  956.       
  957.       public function close() : void
  958.       {
  959.          if(flvplayback_internal::_nc)
  960.          {
  961.             flvplayback_internal::_nc.close();
  962.             _ncConnected = false;
  963.          }
  964.       }
  965.    }
  966. }
  967.